package com.rzj.sys_lab_assistant.service.impl;

import com.rzj.sys_lab_assistant.dao.DepartmentMapper;
import com.rzj.sys_lab_assistant.entity.Department;
import com.rzj.sys_lab_assistant.entity.bo.DepartmentBO;
import com.rzj.sys_lab_assistant.entity.bo.DepartmentTypeBO;
import com.rzj.sys_lab_assistant.service.IDepartmentService;
import com.rzj.sys_lab_assistant.utils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: sys_lab_assistant
 * @description:
 * @author: 作者
 * @create: 2021-06-29 10:42
 */

@Service
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    DepartmentMapper departmentMapper;

    TimeUtils timeUtils;

    @Override
    public List<DepartmentBO> listDepartments() {
        return departmentMapper.listDepartments();
    }

    @Override
    public List<DepartmentBO> listDepartmentsByType(int typeId) {
        return departmentMapper.listDepartmentsByType(typeId);
    }

    @Override
    public List<DepartmentTypeBO> listDepartmentTypes() {
        return departmentMapper.listDepartmentTypes();
    }

    @Override
    public DepartmentBO getDepartmentById(int id) {
        return departmentMapper.getDepartmentById(id);
    }

    @Override
    public int addDepartment(Department department) {
        department.setCreateTime(timeUtils.getTime());
        department.setModifyTime(timeUtils.getTime());
        return departmentMapper.saveDepartment(department);
    }

    @Override
    public int editDepartment(Department department) {
        department.setModifyTime(timeUtils.getTime());
        return departmentMapper.updateDepartment(department);
    }

    @Override
    public int delDepartment(int id) {
        return departmentMapper.deleteDepartment(id);
    }
}
